class EstatesController < ApplicationController
  before_filter :login_required, :except => [:show]
  
  def authorized?(user = current_player())
    return user.admin?
  end
  
  # GET /estates
  # GET /estates.xml
  def index
    @estates = Estate.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @estates }
    end
  end

  # GET /estates/1
  # GET /estates/1.xml
  def show
    @estate = Estate.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @estate }
    end
  end

  # GET /estates/new
  # GET /estates/new.xml
  def new
    @estate = Estate.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @estate }
    end
  end

  # GET /estates/1/edit
  def edit
    @estate = Estate.find(params[:id])
  end

  # POST /estates
  # POST /estates.xml
  def create
    @estate = Estate.new(params[:estate])

    respond_to do |format|
      if @estate.save
        flash[:notice] = 'Estate was successfully created.'
        format.html { redirect_to(@estate) }
        format.xml  { render :xml => @estate, :status => :created, :location => @estate }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @estate.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /estates/1
  # PUT /estates/1.xml
  def update
    @estate = Estate.find(params[:id])

    respond_to do |format|
      if @estate.update_attributes(params[:estate])
        flash[:notice] = 'Estate was successfully updated.'
        format.html { redirect_to(@estate) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @estate.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /estates/1
  # DELETE /estates/1.xml
  def destroy
    @estate = Estate.find(params[:id])
    @estate.destroy

    respond_to do |format|
      format.html { redirect_to(estates_url) }
      format.xml  { head :ok }
    end
  end
end
